from django.db import models
from apps.common.base.models import BaseModel
from apps.user.models import UserModel
from apps.chat.conversation.models import Conversation

class Message(BaseModel):

    '''消息模型'''
    messageType = (
        ("system", "系统消息"),
        ("jytz", "交易通知"),
        ("custom", "用户消息")
    )
    contentType = (
        ("text", "文本"),
        ("image", "图片"),
        ("anotherPay", "代付")
    )
    messageType = models.CharField("消息类型", max_length=100, choices=messageType, default="custom")
    contentType = models.CharField("内容类型", max_length=100, choices=contentType, default="text")
    title = models.CharField("标题", max_length=500, blank=True, null=True, default="")
    content=models.CharField("消息内容", max_length=500, blank=True, null=True, default="")
    isRead=models.BooleanField("是否已读", default=False)

    befrom = models.ForeignKey(UserModel, related_name='befrom_message', verbose_name='发送方', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    to = models.ForeignKey(UserModel, related_name='to_message', verbose_name='接收方', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    conversation = models.ForeignKey(Conversation, related_name='conversationId_message', verbose_name='会话id', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)

    class Meta:
        verbose_name = 'Message'
        verbose_name_plural = verbose_name